﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GsnHelper;
using PetaPoco;
namespace ZhongheCms.Models
{
    public partial class GswTblTieba
    {
        public static List<GswViewTieba> GetTiebaInfo(string sdate, string edate, string keywords, int cusid)
        {
            var sql = "select * from GswViewTieba where ParentId=" + cusid;
            int flag = 0;
            if (InputValid.IsDate(sdate))
            {
                flag = 1;
                sql += " and PubDate>='" + sdate + "'";
            }
            if (InputValid.IsDate(edate))
            {
                flag = 1;
                sql += " and PubDate<='" + edate + "'";
            }
            if (!string.IsNullOrEmpty(keywords))
            {
                flag = 1;
                sql += " and (Title like '%" + keywords + "%' or MemberNickname like '%" + keywords + "%')";
            }
            if(flag==0)
                sql += " and PubDate>='" + DateTime.Today.AddDays(-7).ToShortDateString() + "'";
            sql += " order by PubDate desc";
            var qry = GswViewTieba.Fetch(sql);
            return qry;
        }
    }

    public partial class GswViewTieba
    {
        [ResultColumn]
         public List<GswViewTiebaReply> TiebaReplies { get; set; }
    }
}